package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;

import client.Answers;
import client.Main;
import client.Survey;

import javax.swing.JFrame;

public class Answers_GUI extends JFrame implements ActionListener
{
	public JTable table;
	public String[] columnNames = {"Aid", "Q1", "Q2", "Q3", "Q4", "Q5","Q6"};
	public static Object[][] data = null;
	public JPanel panelExpert1=null;
	public JLabel AnswersSurvey_i=null;
	public JScrollPane ScrollPane = null;
	public JButton Back=null;
	
	void init()
	{
		this.setSize(410,410);
		this.setTitle("Survey Answers");
		this.setLocation((int)Main.dim.getWidth()/2 - (int)this.getPreferredSize().getWidth()/2,(int)Main.dim.getHeight()/4 - (int)this.getPreferredSize().getHeight()/4);
		this.setResizable(false);	
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);	
		this.add(getPanelExpert1());
		this.setEnabled(true);
		this.setVisible(true);
	}
	public Answers_GUI() 
	{		
		super();
		init();	
	}
	JPanel getPanelExpert1()
	{
		if(data.length != 0)
		{	
			table = new JTable(new DefaultTableModel(data,columnNames));			//answers table
			table.setPreferredScrollableViewportSize(new Dimension(300, 300));
			table.setRowHeight(20);
			table.setFont(new Font (Font.SANS_SERIF ,Font.PLAIN,18));
			table.getTableHeader().setFont(new Font (Font.SANS_SERIF ,Font.PLAIN,20));
			table.getTableHeader().setForeground(new Color(147,112,219));
			table.setFillsViewportHeight(true);
			ScrollPane = new JScrollPane(table);
			ScrollPane.setBounds(50, 120, 270, 140);
		
			panelExpert1= new JPanel();
			panelExpert1.setLayout(null);
			AnswersSurvey_i=new JLabel(Survey_GUI.sn[0]+" :  "+Survey_GUI.sn[1]);
			AnswersSurvey_i.setBounds(50, 70, 260, 50);
			AnswersSurvey_i.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,20));
			panelExpert1.add(AnswersSurvey_i);
			panelExpert1.add(getButtonBack());
			panelExpert1.add(ScrollPane);
			panelExpert1.setVisible(true);
			return panelExpert1;
		}
		else 
		{
			JOptionPane.showMessageDialog(null,"Data is empty","Analyze Eror",JOptionPane.ERROR_MESSAGE);
			return null;
		}
	}
 

	JButton getButtonBack()
	{
		if(Back==null)
		{
			Back=new JButton();
			Back.setText("Close");
			Back.setBounds(290,10,100,40);
			Back.addActionListener(this);
		}
		return Back;
	}

	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()== Back)
		{
			this.setEnabled(false);
			this.setVisible(false);
			this.dispose();
		}
		
	}

	
	
}


